package com.td.evo.log.mutate;

import com.krakers.evo.log.EvolutionLogic;
import com.krakers.evo.log.mutate.AbstractMutator;
import com.krakers.evo.obj.DNA;
import com.td.core.obj.TDMap;
import com.td.evo.log.TDPathEvolutionLogic;

/**
 * 
 * @author Inborn
 *
 * @see AbstractMutator
 */
public class TDSimplePathMutator extends AbstractMutator implements TDMap {
	
	private static final int X = BLD_X/2;
	private static final int Y = BLD_Y/2;
	
	/**
	 * @see AbstractMutator#AbstractMutator(double)
	 */
	public TDSimplePathMutator(int elite, double p) {
		super(elite, p);
	}
	
	/**
	 * @see AbstractMutator#AbstractMutator(double, double, double)
	 */
	public TDSimplePathMutator(int elite, double sp, double ep, double dp) {
		super(elite, sp, ep, dp);
	}

	@Override
	protected void mutateInternal(DNA dna) {
		int g = EvolutionLogic.r.nextInt(dna.getSize());
		
		if((g/X)%2 == 0) {
			//popraw srodek
			TDPathEvolutionLogic.fillOnes(dna, g/X);
			dna.setGene(g, 0);
			
			//popraw gore
			if(g/X > 1) {
				int z = TDPathEvolutionLogic.getZeroIndx(dna, g/X - 2);
				TDPathEvolutionLogic.fillOnes(dna, g/X - 1);
				TDPathEvolutionLogic.fillZeros(dna, g/X - 1, z, g%X);
			}
			
			//popraw dol
			if(g/X < Y-2) {
				int z = TDPathEvolutionLogic.getZeroIndx(dna, g/X + 2);
				TDPathEvolutionLogic.fillOnes(dna, g/X + 1);
				TDPathEvolutionLogic.fillZeros(dna, g/X + 1, z, g%X);
			}
		}
	}
}
